@use '../core/style/menu-common';
@use '../core/style/list-common';
@use '../core/style/variables';
@use '../core/style/vendor-prefixes';
@use '../../cdk/a11y/a11y';

$arrow-size: 5px !default;
$arrow-margin: 4px !default;
$panel-max-height: 256px !default;
$item-height: 3em !default;

$placeholder-arrow-space: 2 * ($arrow-size + $arrow-margin);

.mat-select {
  display: inline-block;
  width: 100%;
  outline: none;
}

.mat-select-trigger {
  display: inline-table;
  cursor: pointer;
  position: relative;
  box-sizing: border-box;

  .mat-select-disabled & {
    @include vendor-prefixes.user-select(none);
    cursor: default;
  }
}

.mat-select-value {
  display: table-cell;
  max-width: 0;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mat-select-value-text {
  @include list-common.truncate-line();
}

.mat-select-arrow-wrapper {
  display: table-cell;
  vertical-align: middle;

  // When used in a box appearance form-field the arrow should be shifted up 50%.
  .mat-form-field-appearance-fill & {
    transform: translateY(-50%);
  }

  // When used in a outline form-field the arrow should be shifted up 25%.
  .mat-form-field-appearance-outline & {
    transform: translateY(-25%);
  }

  // When used in a standard appearance form-field the arrow should be shifted up 50%,
  // but only if it's not empty and it has a label.
  .mat-form-field-appearance-standard.mat-form-field-has-label
    .mat-select:not(.mat-select-empty) & {
      transform: translateY(-50%);
    }

  // Animate the arrow position, but only when the transitioning to empty (animate the arrow down)
  // This is in line with the mat-form-field label animation
  .mat-form-field-appearance-standard .mat-select.mat-select-empty & {
    transition: transform variables.$swift-ease-out-duration
      variables.$swift-ease-out-timing-function;
  }

  ._mat-animation-noopable.mat-form-field-appearance-standard .mat-select.mat-select-empty & {
    transition: none;
  }
}

.mat-select-arrow {
  width: 0;
  height: 0;
  border-left: $arrow-size solid transparent;
  border-right: $arrow-size solid transparent;
  border-top: $arrow-size solid;
  margin: 0 $arrow-margin;
}

.mat-select-panel-wrap {
  // Prevents width-issues of mat-select-panel with width: calc(100% + 32px)
  // in IE11 due to the parents display: flex;
  flex-basis: 100%;
}

.mat-select-panel {
  @include menu-common.base();
  padding-top: 0;
  padding-bottom: 0;
  max-height: $panel-max-height;
  min-width: 100%; // prevents some animation twitching and test inconsistencies in IE11
  border-radius: 4px;
  outline: 0;

  @include a11y.high-contrast(active, off) {
    outline: solid 1px;
  }
}

// Override optgroup and option to scale based on font-size of the trigger.
.mat-select-panel {
  .mat-optgroup-label,
  .mat-option {
    font-size: inherit;
    line-height: $item-height;
    height: $item-height;
  }
}

.mat-form-field-type-mat-select {
  &:not(.mat-form-field-disabled) .mat-form-field-flex {
    cursor: pointer;
  }

  .mat-form-field-label {
    width: calc(100% - #{$placeholder-arrow-space});
  }
}

.mat-select-placeholder {
  // Delay the transition until the label has animated about a third of the way through, in
  // order to prevent the placeholder from overlapping for a split second.
  transition: color variables.$swift-ease-out-duration variables.$swift-ease-out-duration / 3
      variables.$swift-ease-out-timing-function;

  ._mat-animation-noopable & {
    transition: none;
  }

  .mat-form-field-hide-placeholder & {
    color: transparent;

    // Overwrite browser specific CSS properties that can overwrite the `color` property.
    // Some developers seem to use this approach to easily overwrite the placeholder / label color.
    -webkit-text-fill-color: transparent;

    // Remove the transition to prevent the placeholder
    // from overlapping when the label comes back down.
    transition: none;
    // Prevents the '...' from showing on the parent element.
    display: block;
  }
}

// Used to prevent inline elements from collapsing if their text bindings
// become empty. This is preferrable to inserting a blank space, because the
// space can be read out by screen readers (see #21725).
.mat-select-min-line:empty::before {
  content: ' ';
  white-space: pre;
  width: 1px;
}
